{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cross-validation for indication-specific mode\n",
    "\n",
    "3. CaDRReS + no bp + ciu + du (du = sample weight based on cancer type)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Read gene expression file and calculate kernel features\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:18.016446Z",
     "start_time": "2020-06-23T11:32:12.677026Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorboard\\compat\\tensorflow_stub\\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorboard\\compat\\tensorflow_stub\\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorboard\\compat\\tensorflow_stub\\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorboard\\compat\\tensorflow_stub\\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorboard\\compat\\tensorflow_stub\\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorboard\\compat\\tensorflow_stub\\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    }
   ],
   "source": [
    "import sys, os, pickle\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "np.set_printoptions(precision=2)\n",
    "from collections import Counter\n",
    "import importlib\n",
    "\n",
    "import matplotlib as mpl\n",
    "mpl.rcParams['figure.dpi']= 300\n",
    "mpl.rc(\"savefig\", dpi=300)\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from scipy import stats\n",
    "\n",
    "scriptpath = '..'\n",
    "sys.path.append(os.path.abspath(scriptpath))\n",
    "\n",
    "from cadrres import pp, model, evaluation, utility"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:18.022882Z",
     "start_time": "2020-06-23T11:32:18.018023Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.14.0'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "tf.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read cell line info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:18.182928Z",
     "start_time": "2020-06-23T11:32:18.025386Z"
    }
   },
   "outputs": [],
   "source": [
    "gdsc_sample_df = pd.read_csv('../data/GDSC/GDSC_tissue_info.csv', index_col=0)\n",
    "gdsc_sample_df.index = gdsc_sample_df.index.astype(str)\n",
    "\n",
    "gdsc_obs_df = pd.read_csv('../data/GDSC/gdsc_all_abs_ic50_bayesian_sigmoid_only9dosages.csv', index_col=0)\n",
    "gdsc_obs_df.index = gdsc_obs_df.index.astype(str)\n",
    "\n",
    "gdsc_sample_list = gdsc_obs_df.index.astype(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:18.190822Z",
     "start_time": "2020-06-23T11:32:18.184558Z"
    }
   },
   "outputs": [],
   "source": [
    "indication_count_df = gdsc_sample_df.groupby(['TCGA_CLASS']).size().sort_values(ascending=False).drop('UNCLASSIFIED')\n",
    "selected_indications = indication_count_df.index[indication_count_df >= 35]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read drug info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:22.489500Z",
     "start_time": "2020-06-23T11:32:22.464026Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(226, 27)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdsc_drug_df = pd.read_csv('../preprocessed_data/GDSC/drug_stat.csv', index_col=0)\n",
    "gdsc_drug_df.index = gdsc_drug_df.index.astype(str)\n",
    "\n",
    "gdsc_drug_list = gdsc_drug_df.index\n",
    "gdsc_drug_df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read gene expression and normalization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:33.452549Z",
     "start_time": "2020-06-23T11:32:25.517940Z"
    }
   },
   "outputs": [],
   "source": [
    "gdsc_log2_exp_df = pd.read_csv('../data/GDSC/GDSC_exp.tsv', sep='\\t', index_col=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sample with both expression and response data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:36.284027Z",
     "start_time": "2020-06-23T11:32:36.278415Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "985"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdsc_sample_list = np.array([s for s in gdsc_sample_list if s in gdsc_log2_exp_df.columns])\n",
    "len(gdsc_sample_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:37.062338Z",
     "start_time": "2020-06-23T11:32:37.054769Z"
    }
   },
   "outputs": [],
   "source": [
    "gdsc_sample_df = gdsc_sample_df.loc[gdsc_sample_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:38.326517Z",
     "start_time": "2020-06-23T11:32:38.308740Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SCLC (60,)\n",
      "LUAD (63,)\n",
      "SKCM (52,)\n",
      "BRCA (49,)\n",
      "COREAD (48,)\n",
      "HNSC (42,)\n",
      "GBM (35,)\n",
      "ESCA (35,)\n"
     ]
    }
   ],
   "source": [
    "gdsc_sample_dict = {}\n",
    "gdsc_obs_df_dict = {}\n",
    "for i in selected_indications:\n",
    "    gdsc_sample_dict[i] = gdsc_sample_df[gdsc_sample_df['TCGA_CLASS']==i].index\n",
    "    gdsc_obs_df_dict[i] = gdsc_obs_df.loc[gdsc_sample_dict[i]]\n",
    "    print (i, gdsc_sample_dict[i].shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:38.903676Z",
     "start_time": "2020-06-23T11:32:38.896647Z"
    }
   },
   "outputs": [],
   "source": [
    "gdsc_obs_df = gdsc_obs_df.loc[gdsc_sample_list, gdsc_drug_list]\n",
    "gdsc_drug_df = gdsc_drug_df.loc[gdsc_drug_list]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculate kernel feature \n",
    "\n",
    "Based on all 985 GDSC samples with gene expression profiles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:32:44.318167Z",
     "start_time": "2020-06-23T11:32:43.549026Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1240121</th>\n",
       "      <th>1240122</th>\n",
       "      <th>1240123</th>\n",
       "      <th>1240124</th>\n",
       "      <th>1240125</th>\n",
       "      <th>1240127</th>\n",
       "      <th>1240128</th>\n",
       "      <th>1240129</th>\n",
       "      <th>1240130</th>\n",
       "      <th>1240131</th>\n",
       "      <th>...</th>\n",
       "      <th>949175</th>\n",
       "      <th>949176</th>\n",
       "      <th>949177</th>\n",
       "      <th>949178</th>\n",
       "      <th>949179</th>\n",
       "      <th>971773</th>\n",
       "      <th>971774</th>\n",
       "      <th>971777</th>\n",
       "      <th>998184</th>\n",
       "      <th>998189</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1240121</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.200762</td>\n",
       "      <td>-0.097257</td>\n",
       "      <td>0.079455</td>\n",
       "      <td>-0.080807</td>\n",
       "      <td>-0.107964</td>\n",
       "      <td>-0.058302</td>\n",
       "      <td>0.079915</td>\n",
       "      <td>0.063199</td>\n",
       "      <td>0.035671</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.129215</td>\n",
       "      <td>-0.179337</td>\n",
       "      <td>-0.095300</td>\n",
       "      <td>-0.112817</td>\n",
       "      <td>-0.186527</td>\n",
       "      <td>-0.088457</td>\n",
       "      <td>-0.143004</td>\n",
       "      <td>-0.189747</td>\n",
       "      <td>-0.259590</td>\n",
       "      <td>-0.054617</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240122</th>\n",
       "      <td>0.200762</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.193214</td>\n",
       "      <td>-0.049567</td>\n",
       "      <td>-0.180749</td>\n",
       "      <td>0.187601</td>\n",
       "      <td>0.042315</td>\n",
       "      <td>0.171160</td>\n",
       "      <td>-0.049354</td>\n",
       "      <td>-0.061332</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.008915</td>\n",
       "      <td>0.042224</td>\n",
       "      <td>0.080204</td>\n",
       "      <td>0.052032</td>\n",
       "      <td>-0.091817</td>\n",
       "      <td>0.007112</td>\n",
       "      <td>0.046598</td>\n",
       "      <td>0.099549</td>\n",
       "      <td>-0.010853</td>\n",
       "      <td>-0.037156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240123</th>\n",
       "      <td>-0.097257</td>\n",
       "      <td>0.193214</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.165331</td>\n",
       "      <td>-0.079250</td>\n",
       "      <td>0.187299</td>\n",
       "      <td>-0.092017</td>\n",
       "      <td>-0.022646</td>\n",
       "      <td>0.057621</td>\n",
       "      <td>-0.160944</td>\n",
       "      <td>...</td>\n",
       "      <td>0.082774</td>\n",
       "      <td>0.044117</td>\n",
       "      <td>0.080209</td>\n",
       "      <td>0.092592</td>\n",
       "      <td>0.025462</td>\n",
       "      <td>-0.139113</td>\n",
       "      <td>0.126919</td>\n",
       "      <td>0.068192</td>\n",
       "      <td>0.098840</td>\n",
       "      <td>0.289321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240124</th>\n",
       "      <td>0.079455</td>\n",
       "      <td>-0.049567</td>\n",
       "      <td>0.165331</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.213386</td>\n",
       "      <td>-0.134121</td>\n",
       "      <td>-0.063749</td>\n",
       "      <td>-0.069065</td>\n",
       "      <td>0.121054</td>\n",
       "      <td>0.002488</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.271613</td>\n",
       "      <td>-0.177998</td>\n",
       "      <td>-0.222713</td>\n",
       "      <td>-0.215761</td>\n",
       "      <td>-0.092428</td>\n",
       "      <td>-0.068879</td>\n",
       "      <td>-0.154265</td>\n",
       "      <td>-0.092515</td>\n",
       "      <td>-0.003545</td>\n",
       "      <td>0.374791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240125</th>\n",
       "      <td>-0.080807</td>\n",
       "      <td>-0.180749</td>\n",
       "      <td>-0.079250</td>\n",
       "      <td>0.213386</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.048241</td>\n",
       "      <td>-0.110779</td>\n",
       "      <td>0.039282</td>\n",
       "      <td>0.270578</td>\n",
       "      <td>0.084228</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.176282</td>\n",
       "      <td>-0.160407</td>\n",
       "      <td>-0.128728</td>\n",
       "      <td>-0.236164</td>\n",
       "      <td>0.028765</td>\n",
       "      <td>0.033600</td>\n",
       "      <td>-0.054744</td>\n",
       "      <td>0.132978</td>\n",
       "      <td>-0.040489</td>\n",
       "      <td>0.017542</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 985 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          1240121   1240122   1240123   1240124   1240125   1240127   1240128  \\\n",
       "1240121  1.000000  0.200762 -0.097257  0.079455 -0.080807 -0.107964 -0.058302   \n",
       "1240122  0.200762  1.000000  0.193214 -0.049567 -0.180749  0.187601  0.042315   \n",
       "1240123 -0.097257  0.193214  1.000000  0.165331 -0.079250  0.187299 -0.092017   \n",
       "1240124  0.079455 -0.049567  0.165331  1.000000  0.213386 -0.134121 -0.063749   \n",
       "1240125 -0.080807 -0.180749 -0.079250  0.213386  1.000000 -0.048241 -0.110779   \n",
       "\n",
       "          1240129   1240130   1240131  ...    949175    949176    949177  \\\n",
       "1240121  0.079915  0.063199  0.035671  ... -0.129215 -0.179337 -0.095300   \n",
       "1240122  0.171160 -0.049354 -0.061332  ... -0.008915  0.042224  0.080204   \n",
       "1240123 -0.022646  0.057621 -0.160944  ...  0.082774  0.044117  0.080209   \n",
       "1240124 -0.069065  0.121054  0.002488  ... -0.271613 -0.177998 -0.222713   \n",
       "1240125  0.039282  0.270578  0.084228  ... -0.176282 -0.160407 -0.128728   \n",
       "\n",
       "           949178    949179    971773    971774    971777    998184    998189  \n",
       "1240121 -0.112817 -0.186527 -0.088457 -0.143004 -0.189747 -0.259590 -0.054617  \n",
       "1240122  0.052032 -0.091817  0.007112  0.046598  0.099549 -0.010853 -0.037156  \n",
       "1240123  0.092592  0.025462 -0.139113  0.126919  0.068192  0.098840  0.289321  \n",
       "1240124 -0.215761 -0.092428 -0.068879 -0.154265 -0.092515 -0.003545  0.374791  \n",
       "1240125 -0.236164  0.028765  0.033600 -0.054744  0.132978 -0.040489  0.017542  \n",
       "\n",
       "[5 rows x 985 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kernel_feature_df = pd.read_csv('../preprocessed_data/GDSC/kernel_features.csv', index_col=0)\n",
    "kernel_feature_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cross validation (5-fold)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Train and predict the validation set\n",
    "\n",
    "- train_model for 'cadrres', 'cadrres-wo-sample-bias'\n",
    "- train_model_logistic_weight (with d_u and c_iu; no sample bias implementation)\n",
    "    - cadrres-wo-sample-bias-weight"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Select indication specific drugs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:33:36.530240Z",
     "start_time": "2020-06-23T11:33:36.527420Z"
    }
   },
   "outputs": [],
   "source": [
    "min_num = 20\n",
    "min_sensitive_percent = 0.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:33:37.288678Z",
     "start_time": "2020-06-23T11:33:37.187233Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Drug ID</th>\n",
       "      <th>1</th>\n",
       "      <th>1001</th>\n",
       "      <th>1003</th>\n",
       "      <th>1004</th>\n",
       "      <th>1005</th>\n",
       "      <th>1006</th>\n",
       "      <th>1007</th>\n",
       "      <th>1008</th>\n",
       "      <th>1009</th>\n",
       "      <th>1010</th>\n",
       "      <th>...</th>\n",
       "      <th>64</th>\n",
       "      <th>71</th>\n",
       "      <th>83</th>\n",
       "      <th>86</th>\n",
       "      <th>87</th>\n",
       "      <th>88</th>\n",
       "      <th>89</th>\n",
       "      <th>9</th>\n",
       "      <th>91</th>\n",
       "      <th>94</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1240121</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240122</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240123</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240124</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1240125</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 226 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Drug ID      1   1001   1003   1004   1005   1006   1007   1008   1009   1010  \\\n",
       "1240121  False   True   True   True   True   True   True  False  False  False   \n",
       "1240122  False   True   True   True  False   True   True  False  False   True   \n",
       "1240123  False  False   True  False  False  False  False  False  False   True   \n",
       "1240124  False  False  False  False  False  False  False  False  False  False   \n",
       "1240125  False  False   True   True  False  False  False  False  False  False   \n",
       "\n",
       "Drug ID  ...     64     71     83     86     87     88     89      9     91  \\\n",
       "1240121  ...  False  False  False  False  False  False  False  False  False   \n",
       "1240122  ...  False  False  False  False  False  False  False  False  False   \n",
       "1240123  ...  False  False  False  False  False  False  False  False  False   \n",
       "1240124  ...  False  False  False  False  False  False  False  False  False   \n",
       "1240125  ...  False  False  False  False  False  False  False  False  False   \n",
       "\n",
       "Drug ID     94  \n",
       "1240121  False  \n",
       "1240122  False  \n",
       "1240123  False  \n",
       "1240124  False  \n",
       "1240125  False  \n",
       "\n",
       "[5 rows x 226 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sensitive_df = gdsc_obs_df <= gdsc_drug_df[['log2_max_conc']].T.values\n",
    "sensitive_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:33:40.700286Z",
     "start_time": "2020-06-23T11:33:40.663309Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SCLC 18 85\n",
      "LUAD 19 73\n",
      "SKCM 16 85\n",
      "BRCA 15 69\n",
      "COREAD 15 79\n",
      "HNSC 13 81\n"
     ]
    }
   ],
   "source": [
    "indication_drug_dict = {}\n",
    "indication_sample_dict = {}\n",
    "\n",
    "for i in selected_indications[0:6]:\n",
    "    \n",
    "    i_sample_list = gdsc_sample_df[gdsc_sample_df['TCGA_CLASS']==i].index\n",
    "    indication_sample_dict[i] = list(i_sample_list.astype(int))\n",
    "    min_num_sensitive = int(np.ceil(min_sensitive_percent * len(i_sample_list)))\n",
    "    \n",
    "    i_count_df = (~gdsc_obs_df.loc[i_sample_list].isnull()).sum()\n",
    "    i_sensitive_df = sensitive_df.loc[i_sample_list].sum()\n",
    "    \n",
    "    i_df = pd.concat([i_count_df, i_sensitive_df], axis=1)\n",
    "    indication_drug_dict[i] = list(i_df[(i_df[0] >= min_num) & (i_df[1] >= min_num_sensitive)].index)\n",
    "    \n",
    "    print (i, min_num_sensitive, len(indication_drug_dict[i]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Train for indication-specific\n",
    "'cadrres-wo-sample-bias-weight-indication'\n",
    "\n",
    "- Indication specific weight: 1-10\n",
    "- Indication specific drugs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:33:43.884386Z",
     "start_time": "2020-06-23T11:33:43.881549Z"
    }
   },
   "outputs": [],
   "source": [
    "output_dir = '../result/cv_pred/'\n",
    "model_spec_name = 'cadrres-wo-sample-bias-weight'\n",
    "indication_specific_degree = 1 # 1 5 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-06-23T11:35:00.147076Z",
     "start_time": "2020-06-23T11:33:53.697666Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fold # 1\n",
      "SCLC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\Dropbox\\Research\\2019_drug_response_heterogeneity\\CaDRReS_depository\\cadrres\\model.py:101: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n",
      "\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\Dropbox\\Research\\2019_drug_response_heterogeneity\\CaDRReS_depository\\cadrres\\model.py:122: The name tf.truncated_normal is deprecated. Please use tf.random.truncated_normal instead.\n",
      "\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\Dropbox\\Research\\2019_drug_response_heterogeneity\\CaDRReS_depository\\cadrres\\model.py:124: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.\n",
      "\n",
      "Train: 56681 out of 66725\n",
      "Starting model training ...\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\Dropbox\\Research\\2019_drug_response_heterogeneity\\CaDRReS_depository\\cadrres\\model.py:550: The name tf.train.GradientDescentOptimizer is deprecated. Please use tf.compat.v1.train.GradientDescentOptimizer instead.\n",
      "\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\anaconda3\\envs\\tf1-14\\lib\\site-packages\\tensorflow\\python\\ops\\math_grad.py:1250: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use tf.where in 2.0, which has the same broadcast rule as np.where\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\Dropbox\\Research\\2019_drug_response_heterogeneity\\CaDRReS_depository\\cadrres\\model.py:552: The name tf.summary.scalar is deprecated. Please use tf.compat.v1.summary.scalar instead.\n",
      "\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\Dropbox\\Research\\2019_drug_response_heterogeneity\\CaDRReS_depository\\cadrres\\model.py:554: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.\n",
      "\n",
      "TF session started ...\n",
      "WARNING:tensorflow:From C:\\Users\\csuph\\Dropbox\\Research\\2019_drug_response_heterogeneity\\CaDRReS_depository\\cadrres\\model.py:564: The name tf.global_variables_initializer is deprecated. Please use tf.compat.v1.global_variables_initializer instead.\n",
      "\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 24.741 (0.01m)\n",
      "MSE train at step 5000: 7.613 (0.38m)\n",
      "MSE train at step 10000: 6.429 (0.76m)\n",
      "MSE train at step 15000: 6.066 (1.14m)\n",
      "MSE train at step 20000: 5.838 (1.52m)\n",
      "MSE train at step 25000: 5.665 (1.90m)\n",
      "MSE train at step 30000: 5.501 (2.27m)\n",
      "MSE train at step 35000: 5.349 (2.65m)\n",
      "MSE train at step 40000: 5.228 (3.03m)\n",
      "MSE train at step 45000: 5.113 (3.40m)\n",
      "MSE train at step 50000: 4.990 (3.78m)\n",
      "MSE train at step 55000: 4.874 (4.15m)\n",
      "MSE train at step 60000: 4.776 (4.52m)\n",
      "MSE train at step 65000: 4.681 (4.90m)\n",
      "MSE train at step 70000: 4.592 (5.27m)\n",
      "MSE train at step 75000: 4.483 (5.65m)\n",
      "MSE train at step 80000: 4.402 (6.02m)\n",
      "MSE train at step 85000: 4.326 (6.39m)\n",
      "MSE train at step 90000: 4.256 (6.76m)\n",
      "MSE train at step 95000: 4.191 (7.13m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "LUAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 51698 out of 57305\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.001 (0.00m)\n",
      "MSE train at step 5000: 7.061 (0.38m)\n",
      "MSE train at step 10000: 6.080 (0.76m)\n",
      "MSE train at step 15000: 5.764 (1.14m)\n",
      "MSE train at step 20000: 5.569 (1.51m)\n",
      "MSE train at step 25000: 5.397 (1.88m)\n",
      "MSE train at step 30000: 5.250 (2.26m)\n",
      "MSE train at step 35000: 5.105 (2.64m)\n",
      "MSE train at step 40000: 4.978 (3.01m)\n",
      "MSE train at step 45000: 4.853 (3.39m)\n",
      "MSE train at step 50000: 4.736 (3.76m)\n",
      "MSE train at step 55000: 4.628 (4.14m)\n",
      "MSE train at step 60000: 4.528 (4.51m)\n",
      "MSE train at step 65000: 4.433 (4.89m)\n",
      "MSE train at step 70000: 4.347 (5.26m)\n",
      "MSE train at step 75000: 4.269 (5.63m)\n",
      "MSE train at step 80000: 4.194 (6.00m)\n",
      "MSE train at step 85000: 4.128 (6.38m)\n",
      "MSE train at step 90000: 4.066 (6.75m)\n",
      "MSE train at step 95000: 4.008 (7.13m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "SKCM\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 60290 out of 66725\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.612 (0.00m)\n",
      "MSE train at step 5000: 7.106 (0.38m)\n",
      "MSE train at step 10000: 5.787 (0.76m)\n",
      "MSE train at step 15000: 5.436 (1.14m)\n",
      "MSE train at step 20000: 5.239 (1.51m)\n",
      "MSE train at step 25000: 5.094 (1.89m)\n",
      "MSE train at step 30000: 4.961 (2.27m)\n",
      "MSE train at step 35000: 4.838 (2.65m)\n",
      "MSE train at step 40000: 4.724 (3.02m)\n",
      "MSE train at step 45000: 4.611 (3.40m)\n",
      "MSE train at step 50000: 4.510 (3.78m)\n",
      "MSE train at step 55000: 4.423 (4.16m)\n",
      "MSE train at step 60000: 4.343 (4.53m)\n",
      "MSE train at step 65000: 4.267 (4.91m)\n",
      "MSE train at step 70000: 4.193 (5.29m)\n",
      "MSE train at step 75000: 4.119 (5.66m)\n",
      "MSE train at step 80000: 4.055 (6.04m)\n",
      "MSE train at step 85000: 3.996 (6.42m)\n",
      "MSE train at step 90000: 3.941 (6.80m)\n",
      "MSE train at step 95000: 3.887 (7.17m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "BRCA\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 49040 out of 54165\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.539 (0.00m)\n",
      "MSE train at step 5000: 6.951 (0.38m)\n",
      "MSE train at step 10000: 6.032 (0.75m)\n",
      "MSE train at step 15000: 5.725 (1.12m)\n",
      "MSE train at step 20000: 5.527 (1.49m)\n",
      "MSE train at step 25000: 5.359 (1.86m)\n",
      "MSE train at step 30000: 5.194 (2.22m)\n",
      "MSE train at step 35000: 5.040 (2.59m)\n",
      "MSE train at step 40000: 4.905 (2.96m)\n",
      "MSE train at step 45000: 4.791 (3.33m)\n",
      "MSE train at step 50000: 4.674 (3.70m)\n",
      "MSE train at step 55000: 4.578 (4.07m)\n",
      "MSE train at step 60000: 4.483 (4.44m)\n",
      "MSE train at step 65000: 4.388 (4.81m)\n",
      "MSE train at step 70000: 4.302 (5.18m)\n",
      "MSE train at step 75000: 4.220 (5.55m)\n",
      "MSE train at step 80000: 4.150 (5.92m)\n",
      "MSE train at step 85000: 4.080 (6.29m)\n",
      "MSE train at step 90000: 4.020 (6.66m)\n",
      "MSE train at step 95000: 3.957 (7.03m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "COREAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56195 out of 62015\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.911 (0.00m)\n",
      "MSE train at step 5000: 7.150 (0.39m)\n",
      "MSE train at step 10000: 6.055 (0.77m)\n",
      "MSE train at step 15000: 5.707 (1.16m)\n",
      "MSE train at step 20000: 5.509 (1.54m)\n",
      "MSE train at step 25000: 5.347 (1.92m)\n",
      "MSE train at step 30000: 5.198 (2.30m)\n",
      "MSE train at step 35000: 5.060 (2.68m)\n",
      "MSE train at step 40000: 4.926 (3.06m)\n",
      "MSE train at step 45000: 4.804 (3.44m)\n",
      "MSE train at step 50000: 4.685 (3.82m)\n",
      "MSE train at step 55000: 4.583 (4.20m)\n",
      "MSE train at step 60000: 4.476 (4.58m)\n",
      "MSE train at step 65000: 4.386 (4.96m)\n",
      "MSE train at step 70000: 4.301 (5.34m)\n",
      "MSE train at step 75000: 4.224 (5.72m)\n",
      "MSE train at step 80000: 4.157 (6.11m)\n",
      "MSE train at step 85000: 4.098 (6.49m)\n",
      "MSE train at step 90000: 4.037 (6.87m)\n",
      "MSE train at step 95000: 3.982 (7.25m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "HNSC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 57149 out of 63585\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.018 (0.00m)\n",
      "MSE train at step 5000: 7.375 (0.38m)\n",
      "MSE train at step 10000: 6.179 (0.74m)\n",
      "MSE train at step 15000: 5.824 (1.11m)\n",
      "MSE train at step 20000: 5.621 (1.48m)\n",
      "MSE train at step 25000: 5.461 (1.85m)\n",
      "MSE train at step 30000: 5.308 (2.22m)\n",
      "MSE train at step 35000: 5.172 (2.58m)\n",
      "MSE train at step 40000: 5.052 (2.95m)\n",
      "MSE train at step 45000: 4.932 (3.32m)\n",
      "MSE train at step 50000: 4.823 (3.69m)\n",
      "MSE train at step 55000: 4.721 (4.05m)\n",
      "MSE train at step 60000: 4.631 (4.42m)\n",
      "MSE train at step 65000: 4.546 (4.79m)\n",
      "MSE train at step 70000: 4.472 (5.15m)\n",
      "MSE train at step 75000: 4.401 (5.52m)\n",
      "MSE train at step 80000: 4.331 (5.89m)\n",
      "MSE train at step 85000: 4.266 (6.26m)\n",
      "MSE train at step 90000: 4.204 (6.63m)\n",
      "MSE train at step 95000: 4.147 (7.00m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "Fold # 2\n",
      "SCLC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56402 out of 66810\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 24.577 (0.00m)\n",
      "MSE train at step 5000: 7.484 (0.38m)\n",
      "MSE train at step 10000: 6.281 (0.76m)\n",
      "MSE train at step 15000: 5.909 (1.13m)\n",
      "MSE train at step 20000: 5.681 (1.51m)\n",
      "MSE train at step 25000: 5.516 (1.88m)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MSE train at step 30000: 5.364 (2.25m)\n",
      "MSE train at step 35000: 5.228 (2.61m)\n",
      "MSE train at step 40000: 5.107 (2.97m)\n",
      "MSE train at step 45000: 4.991 (3.34m)\n",
      "MSE train at step 50000: 4.883 (3.72m)\n",
      "MSE train at step 55000: 4.785 (4.09m)\n",
      "MSE train at step 60000: 4.693 (4.46m)\n",
      "MSE train at step 65000: 4.602 (4.85m)\n",
      "MSE train at step 70000: 4.521 (5.23m)\n",
      "MSE train at step 75000: 4.440 (5.60m)\n",
      "MSE train at step 80000: 4.361 (5.98m)\n",
      "MSE train at step 85000: 4.288 (6.35m)\n",
      "MSE train at step 90000: 4.215 (6.73m)\n",
      "MSE train at step 95000: 4.145 (7.10m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "LUAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 51572 out of 57378\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 22.921 (0.00m)\n",
      "MSE train at step 5000: 7.035 (0.37m)\n",
      "MSE train at step 10000: 6.000 (0.74m)\n",
      "MSE train at step 15000: 5.662 (1.10m)\n",
      "MSE train at step 20000: 5.457 (1.47m)\n",
      "MSE train at step 25000: 5.296 (1.83m)\n",
      "MSE train at step 30000: 5.158 (2.20m)\n",
      "MSE train at step 35000: 5.038 (2.58m)\n",
      "MSE train at step 40000: 4.921 (2.94m)\n",
      "MSE train at step 45000: 4.821 (3.31m)\n",
      "MSE train at step 50000: 4.725 (3.67m)\n",
      "MSE train at step 55000: 4.620 (4.03m)\n",
      "MSE train at step 60000: 4.526 (4.40m)\n",
      "MSE train at step 65000: 4.439 (4.76m)\n",
      "MSE train at step 70000: 4.363 (5.13m)\n",
      "MSE train at step 75000: 4.285 (5.49m)\n",
      "MSE train at step 80000: 4.210 (5.85m)\n",
      "MSE train at step 85000: 4.141 (6.21m)\n",
      "MSE train at step 90000: 4.074 (6.57m)\n",
      "MSE train at step 95000: 4.014 (6.94m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "SKCM\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 60124 out of 66810\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.549 (0.00m)\n",
      "MSE train at step 5000: 7.031 (0.39m)\n",
      "MSE train at step 10000: 5.749 (0.77m)\n",
      "MSE train at step 15000: 5.398 (1.16m)\n",
      "MSE train at step 20000: 5.202 (1.54m)\n",
      "MSE train at step 25000: 5.055 (1.92m)\n",
      "MSE train at step 30000: 4.924 (2.30m)\n",
      "MSE train at step 35000: 4.820 (2.69m)\n",
      "MSE train at step 40000: 4.714 (3.07m)\n",
      "MSE train at step 45000: 4.620 (3.45m)\n",
      "MSE train at step 50000: 4.537 (3.84m)\n",
      "MSE train at step 55000: 4.459 (4.22m)\n",
      "MSE train at step 60000: 4.383 (4.61m)\n",
      "MSE train at step 65000: 4.310 (4.99m)\n",
      "MSE train at step 70000: 4.240 (5.37m)\n",
      "MSE train at step 75000: 4.174 (5.75m)\n",
      "MSE train at step 80000: 4.113 (6.13m)\n",
      "MSE train at step 85000: 4.049 (6.51m)\n",
      "MSE train at step 90000: 3.987 (6.89m)\n",
      "MSE train at step 95000: 3.924 (7.28m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "BRCA\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 48901 out of 54234\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.503 (0.00m)\n",
      "MSE train at step 5000: 6.930 (0.39m)\n",
      "MSE train at step 10000: 5.955 (0.76m)\n",
      "MSE train at step 15000: 5.638 (1.14m)\n",
      "MSE train at step 20000: 5.431 (1.52m)\n",
      "MSE train at step 25000: 5.256 (1.90m)\n",
      "MSE train at step 30000: 5.105 (2.29m)\n",
      "MSE train at step 35000: 4.977 (2.67m)\n",
      "MSE train at step 40000: 4.856 (3.04m)\n",
      "MSE train at step 45000: 4.747 (3.42m)\n",
      "MSE train at step 50000: 4.642 (3.80m)\n",
      "MSE train at step 55000: 4.542 (4.18m)\n",
      "MSE train at step 60000: 4.452 (4.56m)\n",
      "MSE train at step 65000: 4.371 (4.95m)\n",
      "MSE train at step 70000: 4.285 (5.33m)\n",
      "MSE train at step 75000: 4.204 (5.72m)\n",
      "MSE train at step 80000: 4.131 (6.10m)\n",
      "MSE train at step 85000: 4.057 (6.49m)\n",
      "MSE train at step 90000: 3.986 (6.87m)\n",
      "MSE train at step 95000: 3.921 (7.25m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "COREAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56031 out of 62094\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.867 (0.00m)\n",
      "MSE train at step 5000: 7.181 (0.39m)\n",
      "MSE train at step 10000: 5.966 (0.77m)\n",
      "MSE train at step 15000: 5.626 (1.15m)\n",
      "MSE train at step 20000: 5.420 (1.53m)\n",
      "MSE train at step 25000: 5.255 (1.91m)\n",
      "MSE train at step 30000: 5.120 (2.28m)\n",
      "MSE train at step 35000: 4.998 (2.66m)\n",
      "MSE train at step 40000: 4.887 (3.05m)\n",
      "MSE train at step 45000: 4.780 (3.43m)\n",
      "MSE train at step 50000: 4.671 (3.80m)\n",
      "MSE train at step 55000: 4.579 (4.18m)\n",
      "MSE train at step 60000: 4.494 (4.57m)\n",
      "MSE train at step 65000: 4.412 (4.95m)\n",
      "MSE train at step 70000: 4.341 (5.33m)\n",
      "MSE train at step 75000: 4.265 (5.72m)\n",
      "MSE train at step 80000: 4.189 (6.09m)\n",
      "MSE train at step 85000: 4.121 (6.47m)\n",
      "MSE train at step 90000: 4.060 (6.85m)\n",
      "MSE train at step 95000: 4.000 (7.23m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "HNSC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 57058 out of 63666\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 22.994 (0.00m)\n",
      "MSE train at step 5000: 7.287 (0.38m)\n",
      "MSE train at step 10000: 6.098 (0.76m)\n",
      "MSE train at step 15000: 5.763 (1.14m)\n",
      "MSE train at step 20000: 5.556 (1.51m)\n",
      "MSE train at step 25000: 5.393 (1.89m)\n",
      "MSE train at step 30000: 5.257 (2.27m)\n",
      "MSE train at step 35000: 5.138 (2.65m)\n",
      "MSE train at step 40000: 5.026 (3.03m)\n",
      "MSE train at step 45000: 4.922 (3.41m)\n",
      "MSE train at step 50000: 4.825 (3.79m)\n",
      "MSE train at step 55000: 4.738 (4.17m)\n",
      "MSE train at step 60000: 4.653 (4.54m)\n",
      "MSE train at step 65000: 4.576 (4.92m)\n",
      "MSE train at step 70000: 4.500 (5.30m)\n",
      "MSE train at step 75000: 4.428 (5.68m)\n",
      "MSE train at step 80000: 4.360 (6.06m)\n",
      "MSE train at step 85000: 4.298 (6.43m)\n",
      "MSE train at step 90000: 4.235 (6.81m)\n",
      "MSE train at step 95000: 4.172 (7.19m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "Fold # 3\n",
      "SCLC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56915 out of 66980\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 24.707 (0.00m)\n",
      "MSE train at step 5000: 7.730 (0.39m)\n",
      "MSE train at step 10000: 6.485 (0.77m)\n",
      "MSE train at step 15000: 6.069 (1.14m)\n",
      "MSE train at step 20000: 5.803 (1.52m)\n",
      "MSE train at step 25000: 5.612 (1.89m)\n",
      "MSE train at step 30000: 5.426 (2.26m)\n",
      "MSE train at step 35000: 5.288 (2.63m)\n",
      "MSE train at step 40000: 5.158 (3.00m)\n",
      "MSE train at step 45000: 5.028 (3.37m)\n",
      "MSE train at step 50000: 4.928 (3.74m)\n",
      "MSE train at step 55000: 4.832 (4.11m)\n",
      "MSE train at step 60000: 4.743 (4.48m)\n",
      "MSE train at step 65000: 4.644 (4.86m)\n",
      "MSE train at step 70000: 4.562 (5.23m)\n",
      "MSE train at step 75000: 4.477 (5.60m)\n",
      "MSE train at step 80000: 4.408 (5.98m)\n",
      "MSE train at step 85000: 4.342 (6.36m)\n",
      "MSE train at step 90000: 4.283 (6.72m)\n",
      "MSE train at step 95000: 4.217 (7.09m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "LUAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 51797 out of 57524\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 22.988 (0.00m)\n",
      "MSE train at step 5000: 7.011 (0.38m)\n",
      "MSE train at step 10000: 6.052 (0.75m)\n",
      "MSE train at step 15000: 5.719 (1.13m)\n",
      "MSE train at step 20000: 5.501 (1.50m)\n",
      "MSE train at step 25000: 5.315 (1.87m)\n",
      "MSE train at step 30000: 5.149 (2.24m)\n",
      "MSE train at step 35000: 5.010 (2.61m)\n",
      "MSE train at step 40000: 4.880 (2.98m)\n",
      "MSE train at step 45000: 4.767 (3.34m)\n",
      "MSE train at step 50000: 4.674 (3.71m)\n",
      "MSE train at step 55000: 4.577 (4.08m)\n",
      "MSE train at step 60000: 4.485 (4.44m)\n",
      "MSE train at step 65000: 4.402 (4.81m)\n",
      "MSE train at step 70000: 4.328 (5.18m)\n",
      "MSE train at step 75000: 4.256 (5.55m)\n",
      "MSE train at step 80000: 4.188 (5.91m)\n",
      "MSE train at step 85000: 4.125 (6.27m)\n",
      "MSE train at step 90000: 4.065 (6.64m)\n",
      "MSE train at step 95000: 4.008 (7.00m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "SKCM\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 60386 out of 66980\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.571 (0.00m)\n",
      "MSE train at step 5000: 7.137 (0.37m)\n",
      "MSE train at step 10000: 5.798 (0.74m)\n",
      "MSE train at step 15000: 5.437 (1.10m)\n",
      "MSE train at step 20000: 5.230 (1.47m)\n",
      "MSE train at step 25000: 5.072 (1.83m)\n",
      "MSE train at step 30000: 4.936 (2.19m)\n",
      "MSE train at step 35000: 4.823 (2.56m)\n",
      "MSE train at step 40000: 4.726 (2.92m)\n",
      "MSE train at step 45000: 4.637 (3.29m)\n",
      "MSE train at step 50000: 4.551 (3.65m)\n",
      "MSE train at step 55000: 4.472 (4.02m)\n",
      "MSE train at step 60000: 4.395 (4.39m)\n",
      "MSE train at step 65000: 4.323 (4.75m)\n",
      "MSE train at step 70000: 4.258 (5.12m)\n",
      "MSE train at step 75000: 4.197 (5.49m)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MSE train at step 80000: 4.142 (5.86m)\n",
      "MSE train at step 85000: 4.088 (6.22m)\n",
      "MSE train at step 90000: 4.033 (6.58m)\n",
      "MSE train at step 95000: 3.981 (6.94m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "BRCA\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 49144 out of 54372\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.502 (0.00m)\n",
      "MSE train at step 5000: 7.006 (0.37m)\n",
      "MSE train at step 10000: 6.086 (0.74m)\n",
      "MSE train at step 15000: 5.754 (1.11m)\n",
      "MSE train at step 20000: 5.551 (1.47m)\n",
      "MSE train at step 25000: 5.372 (1.84m)\n",
      "MSE train at step 30000: 5.226 (2.21m)\n",
      "MSE train at step 35000: 5.090 (2.57m)\n",
      "MSE train at step 40000: 4.959 (2.95m)\n",
      "MSE train at step 45000: 4.850 (3.31m)\n",
      "MSE train at step 50000: 4.748 (3.67m)\n",
      "MSE train at step 55000: 4.657 (4.04m)\n",
      "MSE train at step 60000: 4.567 (4.41m)\n",
      "MSE train at step 65000: 4.476 (4.78m)\n",
      "MSE train at step 70000: 4.390 (5.14m)\n",
      "MSE train at step 75000: 4.315 (5.51m)\n",
      "MSE train at step 80000: 4.245 (5.88m)\n",
      "MSE train at step 85000: 4.181 (6.25m)\n",
      "MSE train at step 90000: 4.123 (6.61m)\n",
      "MSE train at step 95000: 4.067 (6.97m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "COREAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56284 out of 62252\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.851 (0.00m)\n",
      "MSE train at step 5000: 7.173 (0.38m)\n",
      "MSE train at step 10000: 5.996 (0.76m)\n",
      "MSE train at step 15000: 5.635 (1.13m)\n",
      "MSE train at step 20000: 5.429 (1.51m)\n",
      "MSE train at step 25000: 5.265 (1.88m)\n",
      "MSE train at step 30000: 5.120 (2.24m)\n",
      "MSE train at step 35000: 4.993 (2.61m)\n",
      "MSE train at step 40000: 4.877 (2.98m)\n",
      "MSE train at step 45000: 4.773 (3.35m)\n",
      "MSE train at step 50000: 4.671 (3.72m)\n",
      "MSE train at step 55000: 4.581 (4.09m)\n",
      "MSE train at step 60000: 4.494 (4.46m)\n",
      "MSE train at step 65000: 4.407 (4.83m)\n",
      "MSE train at step 70000: 4.334 (5.21m)\n",
      "MSE train at step 75000: 4.267 (5.58m)\n",
      "MSE train at step 80000: 4.204 (5.95m)\n",
      "MSE train at step 85000: 4.144 (6.33m)\n",
      "MSE train at step 90000: 4.087 (6.70m)\n",
      "MSE train at step 95000: 4.036 (7.07m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "HNSC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 57263 out of 63828\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 22.972 (0.00m)\n",
      "MSE train at step 5000: 7.269 (0.38m)\n",
      "MSE train at step 10000: 6.112 (0.75m)\n",
      "MSE train at step 15000: 5.764 (1.11m)\n",
      "MSE train at step 20000: 5.556 (1.48m)\n",
      "MSE train at step 25000: 5.402 (1.84m)\n",
      "MSE train at step 30000: 5.265 (2.20m)\n",
      "MSE train at step 35000: 5.149 (2.56m)\n",
      "MSE train at step 40000: 5.049 (2.92m)\n",
      "MSE train at step 45000: 4.954 (3.28m)\n",
      "MSE train at step 50000: 4.858 (3.64m)\n",
      "MSE train at step 55000: 4.770 (4.01m)\n",
      "MSE train at step 60000: 4.683 (4.37m)\n",
      "MSE train at step 65000: 4.596 (4.73m)\n",
      "MSE train at step 70000: 4.517 (5.11m)\n",
      "MSE train at step 75000: 4.450 (5.48m)\n",
      "MSE train at step 80000: 4.388 (5.86m)\n",
      "MSE train at step 85000: 4.324 (6.23m)\n",
      "MSE train at step 90000: 4.262 (6.60m)\n",
      "MSE train at step 95000: 4.205 (6.98m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "Fold # 4\n",
      "SCLC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56915 out of 67150\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 24.706 (0.00m)\n",
      "MSE train at step 5000: 7.614 (0.40m)\n",
      "MSE train at step 10000: 6.359 (0.79m)\n",
      "MSE train at step 15000: 5.958 (1.18m)\n",
      "MSE train at step 20000: 5.717 (1.57m)\n",
      "MSE train at step 25000: 5.530 (1.96m)\n",
      "MSE train at step 30000: 5.362 (2.35m)\n",
      "MSE train at step 35000: 5.219 (2.73m)\n",
      "MSE train at step 40000: 5.087 (3.12m)\n",
      "MSE train at step 45000: 4.979 (3.51m)\n",
      "MSE train at step 50000: 4.866 (3.90m)\n",
      "MSE train at step 55000: 4.747 (4.29m)\n",
      "MSE train at step 60000: 4.619 (4.68m)\n",
      "MSE train at step 65000: 4.534 (5.07m)\n",
      "MSE train at step 70000: 4.461 (5.46m)\n",
      "MSE train at step 75000: 4.388 (5.85m)\n",
      "MSE train at step 80000: 4.322 (6.24m)\n",
      "MSE train at step 85000: 4.263 (6.63m)\n",
      "MSE train at step 90000: 4.200 (7.02m)\n",
      "MSE train at step 95000: 4.142 (7.41m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "LUAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 51880 out of 57670\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.018 (0.00m)\n",
      "MSE train at step 5000: 7.014 (0.39m)\n",
      "MSE train at step 10000: 5.996 (0.77m)\n",
      "MSE train at step 15000: 5.677 (1.16m)\n",
      "MSE train at step 20000: 5.471 (1.54m)\n",
      "MSE train at step 25000: 5.300 (1.91m)\n",
      "MSE train at step 30000: 5.132 (2.29m)\n",
      "MSE train at step 35000: 4.993 (2.66m)\n",
      "MSE train at step 40000: 4.862 (3.04m)\n",
      "MSE train at step 45000: 4.752 (3.41m)\n",
      "MSE train at step 50000: 4.657 (3.78m)\n",
      "MSE train at step 55000: 4.572 (4.16m)\n",
      "MSE train at step 60000: 4.491 (4.53m)\n",
      "MSE train at step 65000: 4.413 (4.90m)\n",
      "MSE train at step 70000: 4.343 (5.27m)\n",
      "MSE train at step 75000: 4.281 (5.65m)\n",
      "MSE train at step 80000: 4.220 (6.03m)\n",
      "MSE train at step 85000: 4.163 (6.40m)\n",
      "MSE train at step 90000: 4.109 (6.78m)\n",
      "MSE train at step 95000: 4.057 (7.15m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "SKCM\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 60523 out of 67150\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.575 (0.00m)\n",
      "MSE train at step 5000: 7.065 (0.39m)\n",
      "MSE train at step 10000: 5.758 (0.77m)\n",
      "MSE train at step 15000: 5.397 (1.16m)\n",
      "MSE train at step 20000: 5.186 (1.54m)\n",
      "MSE train at step 25000: 5.041 (1.92m)\n",
      "MSE train at step 30000: 4.912 (2.31m)\n",
      "MSE train at step 35000: 4.794 (2.69m)\n",
      "MSE train at step 40000: 4.690 (3.07m)\n",
      "MSE train at step 45000: 4.594 (3.46m)\n",
      "MSE train at step 50000: 4.506 (3.84m)\n",
      "MSE train at step 55000: 4.426 (4.23m)\n",
      "MSE train at step 60000: 4.350 (4.62m)\n",
      "MSE train at step 65000: 4.284 (5.00m)\n",
      "MSE train at step 70000: 4.215 (5.39m)\n",
      "MSE train at step 75000: 4.156 (5.77m)\n",
      "MSE train at step 80000: 4.094 (6.16m)\n",
      "MSE train at step 85000: 4.041 (6.56m)\n",
      "MSE train at step 90000: 3.994 (6.96m)\n",
      "MSE train at step 95000: 3.950 (7.34m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "BRCA\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 49208 out of 54510\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.702 (0.00m)\n",
      "MSE train at step 5000: 7.024 (0.38m)\n",
      "MSE train at step 10000: 6.050 (0.75m)\n",
      "MSE train at step 15000: 5.727 (1.12m)\n",
      "MSE train at step 20000: 5.511 (1.48m)\n",
      "MSE train at step 25000: 5.324 (1.83m)\n",
      "MSE train at step 30000: 5.164 (2.20m)\n",
      "MSE train at step 35000: 5.025 (2.57m)\n",
      "MSE train at step 40000: 4.890 (2.94m)\n",
      "MSE train at step 45000: 4.774 (3.30m)\n",
      "MSE train at step 50000: 4.674 (3.66m)\n",
      "MSE train at step 55000: 4.579 (4.02m)\n",
      "MSE train at step 60000: 4.488 (4.39m)\n",
      "MSE train at step 65000: 4.408 (4.75m)\n",
      "MSE train at step 70000: 4.335 (5.12m)\n",
      "MSE train at step 75000: 4.269 (5.48m)\n",
      "MSE train at step 80000: 4.195 (5.85m)\n",
      "MSE train at step 85000: 4.130 (6.20m)\n",
      "MSE train at step 90000: 4.068 (6.56m)\n",
      "MSE train at step 95000: 4.011 (6.92m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "COREAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56406 out of 62410\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.931 (0.00m)\n",
      "MSE train at step 5000: 7.208 (0.37m)\n",
      "MSE train at step 10000: 5.967 (0.75m)\n",
      "MSE train at step 15000: 5.632 (1.12m)\n",
      "MSE train at step 20000: 5.431 (1.49m)\n",
      "MSE train at step 25000: 5.253 (1.86m)\n",
      "MSE train at step 30000: 5.106 (2.23m)\n",
      "MSE train at step 35000: 4.981 (2.60m)\n",
      "MSE train at step 40000: 4.860 (2.97m)\n",
      "MSE train at step 45000: 4.755 (3.34m)\n",
      "MSE train at step 50000: 4.653 (3.70m)\n",
      "MSE train at step 55000: 4.563 (4.07m)\n",
      "MSE train at step 60000: 4.487 (4.43m)\n",
      "MSE train at step 65000: 4.413 (4.80m)\n",
      "MSE train at step 70000: 4.347 (5.17m)\n",
      "MSE train at step 75000: 4.287 (5.53m)\n",
      "MSE train at step 80000: 4.225 (5.89m)\n",
      "MSE train at step 85000: 4.161 (6.25m)\n",
      "MSE train at step 90000: 4.100 (6.62m)\n",
      "MSE train at step 95000: 4.041 (6.99m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "HNSC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 57364 out of 63990\n",
      "Starting model training ...\n",
      "TF session started ...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 22.972 (0.00m)\n",
      "MSE train at step 5000: 7.268 (0.38m)\n",
      "MSE train at step 10000: 6.128 (0.75m)\n",
      "MSE train at step 15000: 5.767 (1.13m)\n",
      "MSE train at step 20000: 5.540 (1.50m)\n",
      "MSE train at step 25000: 5.373 (1.89m)\n",
      "MSE train at step 30000: 5.224 (2.27m)\n",
      "MSE train at step 35000: 5.098 (2.64m)\n",
      "MSE train at step 40000: 4.983 (3.00m)\n",
      "MSE train at step 45000: 4.886 (3.37m)\n",
      "MSE train at step 50000: 4.782 (3.74m)\n",
      "MSE train at step 55000: 4.690 (4.11m)\n",
      "MSE train at step 60000: 4.603 (4.48m)\n",
      "MSE train at step 65000: 4.530 (4.86m)\n",
      "MSE train at step 70000: 4.464 (5.24m)\n",
      "MSE train at step 75000: 4.400 (5.61m)\n",
      "MSE train at step 80000: 4.334 (5.98m)\n",
      "MSE train at step 85000: 4.280 (6.34m)\n",
      "MSE train at step 90000: 4.227 (6.72m)\n",
      "MSE train at step 95000: 4.178 (7.09m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "Fold # 5\n",
      "SCLC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56927 out of 67235\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 24.637 (0.00m)\n",
      "MSE train at step 5000: 7.706 (0.41m)\n",
      "MSE train at step 10000: 6.506 (0.81m)\n",
      "MSE train at step 15000: 6.161 (1.21m)\n",
      "MSE train at step 20000: 5.942 (1.61m)\n",
      "MSE train at step 25000: 5.745 (2.00m)\n",
      "MSE train at step 30000: 5.584 (2.39m)\n",
      "MSE train at step 35000: 5.426 (2.78m)\n",
      "MSE train at step 40000: 5.289 (3.16m)\n",
      "MSE train at step 45000: 5.165 (3.55m)\n",
      "MSE train at step 50000: 5.047 (3.94m)\n",
      "MSE train at step 55000: 4.938 (4.34m)\n",
      "MSE train at step 60000: 4.838 (4.74m)\n",
      "MSE train at step 65000: 4.738 (5.13m)\n",
      "MSE train at step 70000: 4.655 (5.51m)\n",
      "MSE train at step 75000: 4.569 (5.90m)\n",
      "MSE train at step 80000: 4.488 (6.28m)\n",
      "MSE train at step 85000: 4.415 (6.67m)\n",
      "MSE train at step 90000: 4.352 (7.05m)\n",
      "MSE train at step 95000: 4.275 (7.44m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "LUAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 51885 out of 57743\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 22.918 (0.00m)\n",
      "MSE train at step 5000: 7.198 (0.39m)\n",
      "MSE train at step 10000: 6.152 (0.76m)\n",
      "MSE train at step 15000: 5.840 (1.14m)\n",
      "MSE train at step 20000: 5.639 (1.52m)\n",
      "MSE train at step 25000: 5.469 (1.89m)\n",
      "MSE train at step 30000: 5.320 (2.28m)\n",
      "MSE train at step 35000: 5.166 (2.67m)\n",
      "MSE train at step 40000: 5.050 (3.05m)\n",
      "MSE train at step 45000: 4.930 (3.44m)\n",
      "MSE train at step 50000: 4.825 (3.81m)\n",
      "MSE train at step 55000: 4.724 (4.19m)\n",
      "MSE train at step 60000: 4.633 (4.56m)\n",
      "MSE train at step 65000: 4.545 (4.94m)\n",
      "MSE train at step 70000: 4.460 (5.31m)\n",
      "MSE train at step 75000: 4.378 (5.69m)\n",
      "MSE train at step 80000: 4.305 (6.06m)\n",
      "MSE train at step 85000: 4.239 (6.44m)\n",
      "MSE train at step 90000: 4.178 (6.82m)\n",
      "MSE train at step 95000: 4.124 (7.20m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "SKCM\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 60473 out of 67235\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.384 (0.00m)\n",
      "MSE train at step 5000: 7.132 (0.38m)\n",
      "MSE train at step 10000: 5.915 (0.76m)\n",
      "MSE train at step 15000: 5.546 (1.14m)\n",
      "MSE train at step 20000: 5.337 (1.52m)\n",
      "MSE train at step 25000: 5.176 (1.89m)\n",
      "MSE train at step 30000: 5.038 (2.27m)\n",
      "MSE train at step 35000: 4.908 (2.64m)\n",
      "MSE train at step 40000: 4.797 (3.02m)\n",
      "MSE train at step 45000: 4.683 (3.40m)\n",
      "MSE train at step 50000: 4.586 (3.77m)\n",
      "MSE train at step 55000: 4.499 (4.15m)\n",
      "MSE train at step 60000: 4.420 (4.53m)\n",
      "MSE train at step 65000: 4.345 (4.90m)\n",
      "MSE train at step 70000: 4.267 (5.28m)\n",
      "MSE train at step 75000: 4.200 (5.66m)\n",
      "MSE train at step 80000: 4.141 (6.03m)\n",
      "MSE train at step 85000: 4.087 (6.41m)\n",
      "MSE train at step 90000: 4.038 (6.78m)\n",
      "MSE train at step 95000: 3.986 (7.16m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "BRCA\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 49207 out of 54579\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.477 (0.00m)\n",
      "MSE train at step 5000: 7.068 (0.38m)\n",
      "MSE train at step 10000: 6.144 (0.75m)\n",
      "MSE train at step 15000: 5.822 (1.12m)\n",
      "MSE train at step 20000: 5.581 (1.49m)\n",
      "MSE train at step 25000: 5.386 (1.87m)\n",
      "MSE train at step 30000: 5.232 (2.25m)\n",
      "MSE train at step 35000: 5.090 (2.62m)\n",
      "MSE train at step 40000: 4.958 (3.00m)\n",
      "MSE train at step 45000: 4.832 (3.37m)\n",
      "MSE train at step 50000: 4.719 (3.74m)\n",
      "MSE train at step 55000: 4.611 (4.12m)\n",
      "MSE train at step 60000: 4.521 (4.49m)\n",
      "MSE train at step 65000: 4.436 (4.87m)\n",
      "MSE train at step 70000: 4.357 (5.24m)\n",
      "MSE train at step 75000: 4.288 (5.61m)\n",
      "MSE train at step 80000: 4.214 (5.98m)\n",
      "MSE train at step 85000: 4.144 (6.36m)\n",
      "MSE train at step 90000: 4.082 (6.73m)\n",
      "MSE train at step 95000: 4.025 (7.10m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "COREAD\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 56372 out of 62489\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 23.844 (0.00m)\n",
      "MSE train at step 5000: 7.241 (0.39m)\n",
      "MSE train at step 10000: 6.073 (0.77m)\n",
      "MSE train at step 15000: 5.729 (1.15m)\n",
      "MSE train at step 20000: 5.516 (1.53m)\n",
      "MSE train at step 25000: 5.349 (1.91m)\n",
      "MSE train at step 30000: 5.199 (2.29m)\n",
      "MSE train at step 35000: 5.070 (2.68m)\n",
      "MSE train at step 40000: 4.944 (3.06m)\n",
      "MSE train at step 45000: 4.840 (3.44m)\n",
      "MSE train at step 50000: 4.741 (3.82m)\n",
      "MSE train at step 55000: 4.649 (4.20m)\n",
      "MSE train at step 60000: 4.564 (4.58m)\n",
      "MSE train at step 65000: 4.487 (4.97m)\n",
      "MSE train at step 70000: 4.412 (5.35m)\n",
      "MSE train at step 75000: 4.340 (5.73m)\n",
      "MSE train at step 80000: 4.276 (6.11m)\n",
      "MSE train at step 85000: 4.218 (6.50m)\n",
      "MSE train at step 90000: 4.161 (6.88m)\n",
      "MSE train at step 95000: 4.109 (7.26m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n",
      "HNSC\n",
      "Getting data ...\n",
      "Initializing the model ...\n",
      "Train: 57382 out of 64071\n",
      "Starting model training ...\n",
      "TF session started ...\n",
      "Starting 1st iteration ...\n",
      "MSE train at step 0: 22.916 (0.00m)\n",
      "MSE train at step 5000: 7.394 (0.39m)\n",
      "MSE train at step 10000: 6.224 (0.77m)\n",
      "MSE train at step 15000: 5.876 (1.15m)\n",
      "MSE train at step 20000: 5.662 (1.53m)\n",
      "MSE train at step 25000: 5.483 (1.91m)\n",
      "MSE train at step 30000: 5.332 (2.29m)\n",
      "MSE train at step 35000: 5.214 (2.67m)\n",
      "MSE train at step 40000: 5.104 (3.05m)\n",
      "MSE train at step 45000: 4.988 (3.43m)\n",
      "MSE train at step 50000: 4.876 (3.81m)\n",
      "MSE train at step 55000: 4.787 (4.19m)\n",
      "MSE train at step 60000: 4.695 (4.58m)\n",
      "MSE train at step 65000: 4.617 (4.96m)\n",
      "MSE train at step 70000: 4.545 (5.34m)\n",
      "MSE train at step 75000: 4.478 (5.72m)\n",
      "MSE train at step 80000: 4.406 (6.10m)\n",
      "MSE train at step 85000: 4.343 (6.48m)\n",
      "MSE train at step 90000: 4.281 (6.86m)\n",
      "MSE train at step 95000: 4.223 (7.24m)\n",
      "Saving model parameters and predictions ...\n",
      "DONE\n"
     ]
    }
   ],
   "source": [
    "for k in range(1, 5+1):\n",
    "    \n",
    "    print (\"Fold #\", k)\n",
    "\n",
    "    X_train = pd.read_csv('../preprocessed_data/GDSC/cv_data/{}_5f_{}.csv'.format('X_train', k), index_col=0)\n",
    "    X_test = pd.read_csv('../preprocessed_data/GDSC/cv_data/{}_5f_{}.csv'.format('X_test', k), index_col=0)\n",
    "    \n",
    "    for i in selected_indications[0:6]:\n",
    "        \n",
    "        print (i)\n",
    "    \n",
    "        Y_test = pd.read_csv('../preprocessed_data/GDSC/cv_data/{}_5f_{}.csv'.format('Y_test', k), index_col=0)\n",
    "        Y_train = pd.read_csv('../preprocessed_data/GDSC/cv_data/{}_5f_{}.csv'.format('Y_train', k), index_col=0)\n",
    "\n",
    "        # select drugs\n",
    "        Y_test = Y_test[indication_drug_dict[i]]\n",
    "        Y_train = Y_train[indication_drug_dict[i]]\n",
    "        \n",
    "        #########################\n",
    "\n",
    "        ##### Prepare x0 for calculating logistic sample weigh (o_i) #####\n",
    "\n",
    "        sample_weights_logistic_x0_df = model.get_sample_weights_logistic_x0(gdsc_drug_df, 'log2_max_conc', X_train.index)\n",
    "\n",
    "        ##### Prepare indication weight (skip for this analysis = set all to 1) #####\n",
    "\n",
    "        indication_weight_df = pd.DataFrame(np.ones(Y_train.shape), index=Y_train.index, columns=Y_train.columns)\n",
    "        i_sample_list = [cl for cl in indication_sample_dict[i] if cl in X_train.index]\n",
    "        indication_weight_df.loc[i_sample_list, :] = indication_weight_df.loc[i_sample_list, :] * indication_specific_degree\n",
    "\n",
    "        #########################\n",
    "\n",
    "        if model_spec_name in ['cadrres', 'cadrres-wo-sample-bias']:\n",
    "            cadrres_model_dict, cadrres_output_dict = model.train_model(Y_train, X_train, Y_test, X_test, 10, 0.0, 100000, 0.01, model_spec_name=model_spec_name, save_interval=5000, output_dir=output_dir)\n",
    "        elif model_spec_name in ['cadrres-wo-sample-bias-weight']:\n",
    "            cadrres_model_dict, cadrres_output_dict = model.train_model_logistic_weight(Y_train, X_train, Y_test, X_test, sample_weights_logistic_x0_df, indication_weight_df, 10, 0.0, 100000, 0.01, model_spec_name=model_spec_name, save_interval=5000, output_dir=output_dir)\n",
    "\n",
    "        #########################\n",
    "\n",
    "        ##### Save model and data #####\n",
    "        pickle.dump(cadrres_model_dict, open(output_dir + '{}_{}_{}_5f_{}_param_dict.pickle'.format(model_spec_name, i, indication_specific_degree, k), 'wb'))\n",
    "        pickle.dump(cadrres_output_dict, open(output_dir + '{}_{}_{}_5f_{}_output_dict.pickle'.format(model_spec_name, i, indication_specific_degree, k), 'wb'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cadrres_model_dict = pickle.load(open(output_dir + '{}_{}_5f_{}_param_dict.pickle'.format(model_spec_name, i, 1), 'rb'))\n",
    "# cadrres_output_dict = pickle.load(open(output_dir + '{}_{}_5f_{}_output_dict.pickle'.format(model_spec_name, i, 1), 'rb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# y = cadrres_output_dict['pred_test_df'].values.flatten()\n",
    "# x = cadrres_output_dict['obs_test_df'].values.flatten()\n",
    "# plt.scatter(x[~np.isnan(x)], y[~np.isnan(x)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
